home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Games Special 4 / THE BEST OF SELECT Games Special 4 (Select CD-ROM)(1996).iso / dosgames / abuse / lisp / switch.lsp < prev    next >
Lisp/Scheme  |  1995-09-13  |  7KB  |  302 lines

  1. ;; Copyright 1995 Crack dot Com,  All Rights reserved
  2. ;; See licensing information for more details on usage rights
  3.  
  4. (defun switcher_ai () 
  5.   (next_picture)
  6.   (select (aistate)
  7.       (0      ; waiting for player to press, then turn to on
  8.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  9.            (progn
  10.          (play_sound SWITCH_SND 127 (x) (y))
  11.          (set_state running)         
  12.          (set_aistate 1))))
  13.       (1     ; wait for player to let go of button      
  14.        (if (not (with_object (bg) (pressing_action_key)))
  15.            (set_aistate 2)))
  16.       (2     ; wait for player to press, then turn to off
  17.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  18.            (progn
  19.          (play_sound SWITCH_SND 127 (x) (y))
  20.          (set_state stopped)
  21.          (set_aistate 4))))     
  22.        (4     ; wait for player to let go of button
  23.         (if (not (with_object (bg) (pressing_action_key)))
  24.         (set_aistate 0)))
  25.        )
  26. T)
  27.           
  28.  
  29. (defun switch_once_ai () 
  30.   (select (aistate)
  31.       (0      ; waiting for player to press, then turn to on
  32.        (next_picture)
  33.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  34.            (progn
  35.          (print (random 1000))
  36.          (play_sound SWITCH_SND 127 (x) (y))
  37.          (set_state running)
  38.          (set_aistate 1)))))
  39.   T)
  40.      
  41. (defun lower_reload () (lower))   ;; move object below all other objects
  42.      
  43. (def_char SWITCH
  44.   (funs (ai_fun switcher_ai)
  45.     (reload_fun lower_reload))
  46.   (range 0 0)  
  47.   (states "art/misc.spe"
  48.       (stopped '("switch_off1" "switch_off2"))
  49.       (running '("switch_on1"  "switch_on2"))))
  50.  
  51. (def_char SWITCH_ONCE
  52.   (funs (ai_fun switch_once_ai)
  53.     (reload_fun lower_reload))
  54.   (range 0 0)  
  55.   (states "art/misc.spe"
  56.       (stopped '("switch_off1" "switch_off2"))
  57.       (running '("switch_on1"  "switch_on2"))))
  58.  
  59.  
  60. (defun switch_delay_cons ()
  61.   (setq reset_time 14))
  62.  
  63. (def_char SWITCH_DELAY
  64.   (funs (ai_fun switch_delay_ai)
  65.     (reload_fun lower_reload)
  66.     (constructor switch_delay_cons))
  67.   (vars reset_time)
  68.   (fields ("reset_time" "reset time"))
  69.   (range 0 0)  
  70.   (states "art/misc.spe"
  71.       (stopped '("switch_off1" "switch_off2"))
  72.       (running '("switch_on1"  "switch_on2"))))
  73.  
  74.  
  75.  
  76. (defun switch_delay_ai ()
  77.   (select (aistate)
  78.       (0      ; waiting for player to press, then turn to on
  79.        (next_picture)
  80.        (if (and (< (distx) 20) (< (disty) 30) (with_object (bg) (pressing_action_key)))
  81.            (progn
  82.          (print (random 1000))
  83.          (play_sound SWITCH_SND 127 (x) (y))
  84.          (set_state running)
  85.          (set_aistate 1))))
  86.       (1     ; wait for player to let go of button
  87.        (if (not (with_object (bg) (pressing_action_key)))
  88.            (set_aistate 2)))
  89.       (2     ; wait for reset time
  90.        (if (> (state_time) reset_time)
  91.            (progn
  92.          (play_sound SWITCH_SND 127 (x) (y))
  93.          (set_state stopped)
  94.          (set_aistate 0)))))
  95. T)
  96.  
  97.  
  98. (defun switch_mover_ai ()
  99.   (if (> (total_objects) 1)
  100.       (select (aistate)
  101.           (0 (if (not (eq (with_object (get_object 0) (aistate)) 0))             
  102.              (let ((mex (x))
  103.                (mey (y)))
  104.                (if (eq (xvel) 0)
  105.                (progn
  106.                  (with_object (get_object 1)
  107.                       (progn
  108.                         (set_x mex)
  109.                         (set_y mey)
  110.                         (set_fade_count 15)
  111.                         ))
  112.                  (set_aistate 1)
  113.                  T)
  114.              (with_object (get_object 1)
  115.                       (progn
  116.                     (set_x mex)
  117.                     (set_y mey)
  118.                     nil))))
  119.            T))
  120.           (1 (let ((count (with_object (get_object 1) (fade_count))))
  121.            (if (equal count 0)
  122.                nil
  123.              (progn
  124.                (with_object (get_object 1) (set_fade_count (- count 1)))
  125.                T)))))
  126.                   
  127.     nil))
  128.  
  129. (def_char SWITCH_MOVER
  130.   (funs (ai_fun   switch_mover_ai)
  131.     (draw_fun dev_draw))
  132.   (range 0 0)
  133.   (states "art/misc.spe" (stopped "switch_mover")))
  134.  
  135.  
  136.  
  137. (defun sensor_cons ()
  138.   (set_aitype 1)
  139.   (add_hp -10))
  140.   
  141.  
  142. /* -- compiled code
  143. (defun sensor_ai ()
  144.   (if (eq (aistate) 0)
  145.       (if (and (< (distx) (xvel)) (< (disty) (yvel)))
  146.       (progn 
  147.         (if (eq (hp) 0)  ;; don't time out
  148.         (set_aistate 1)
  149.           (set_aistate (hp)))
  150.         (set_state blocking))
  151.     (set_state stopped))
  152.  
  153.     (if (eq (hp) 0)
  154.         (if (or (> (distx) (xacel)) (> (disty) (yacel)))        
  155.         (set_aistate 0))
  156.       (set_aistate (- (aistate) 1))))
  157. T) */
  158.  
  159. (defun sensor_draw ()
  160.   (if (edit_mode) 
  161.       (progn
  162.     (draw)
  163.     (let ((x1 (- (x) (xvel)))
  164.           (y1 (- (y) (yvel)))
  165.           (x2 (+ (x) (xvel)))
  166.           (y2 (+ (y) (yvel)))
  167.           (c  (find_rgb 0 255 0)))
  168.       (draw_line x1 y1 x2 y1 c)
  169.       (draw_line x2 y1 x2 y2 c)
  170.       (draw_line x2 y2 x1 y2 c)
  171.       (draw_line x1 y2 x1 y1 c))
  172.  
  173.     (let ((x1 (- (x) (xacel)))
  174.           (y1 (- (y) (yacel)))
  175.           (x2 (+ (x) (xacel)))
  176.           (y2 (+ (y) (yacel)))
  177.           (c  (find_rgb 255 0 0)))
  178.       (draw_line x1 y1 x2 y1 c)
  179.       (draw_line x2 y1 x2 y2 c)
  180.       (draw_line x2 y2 x1 y2 c)
  181.       (draw_line x1 y2 x1 y1 c)))
  182.  
  183.  
  184.     nil))
  185.  
  186. (defun sensor_ct ()
  187.   (select (aitype)
  188.       (1 (set_xvel 50)
  189.          (set_yvel 50)
  190.          (set_xacel 100)
  191.          (set_yacel 100))
  192.       (2 (set_xvel 50)
  193.          (set_yvel 30)
  194.          (set_xacel 100)
  195.          (set_yacel 50))
  196.       (3 (set_xvel 50)
  197.          (set_yvel 15)
  198.          (set_xacel 100)
  199.          (set_yacel 30))))
  200.  
  201. (def_char SENSOR
  202.   (range 100 100)
  203.   (funs (ai_fun      sensor_ai)
  204.     (draw_fun    sensor_draw)
  205.     (type_change_fun sensor_ct)
  206.     (constructor sensor_cons))
  207.   (vars unoffable)
  208.   (fields ("xvel" "(on) x dist")
  209.        ("yvel" "(on) y dist")
  210.        ("xacel" "(off) x dist")
  211.        ("yacel" "(off) y dist")
  212.        ("hp"    "(off) reset time")
  213.        ("unoffable" "unoffable (1=yes)")
  214.        ("aistate" "current state"))
  215.   (states "art/misc.spe"
  216.       (stopped "off")
  217.       (blocking "on")))
  218.             
  219. /*
  220. (defun sensor_linker_ai ()
  221.   (if (eq (aistate) 0)
  222.       (if (and (< (distx) (xvel)) (< (disty) (yvel)))
  223.       (progn 
  224.         (if (eq (hp) 0)  ;; don't time out
  225.         (set_aistate 1)
  226.           (set_aistate (hp)))
  227.         (set_state blocking))
  228.     (set_state stopped))
  229.  
  230.     (if (eq (hp) 0)
  231.     (if (or (> (distx) (xacel)) (> (disty) (yacel)))        
  232.         (set_aistate 0))
  233.       (set_aistate (- (aistate) 1)))))
  234.  
  235.  
  236.  
  237. (def_char SENSOR_LINKER
  238.   (range 100 100)
  239.   (funs (ai_fun sensor_linker_ai)
  240.     (draw_fun sensor_draw)
  241.     (constructor sensor_cons))
  242.   (vars offable)
  243.   (fields ("xvel" "(on) x dist")
  244.        ("yvel" "(on) y dist")
  245.        ("xacel" "(off) x dist")
  246.        ("yacel" "(off) y dist")
  247.        ("hp"    "(off) reset time")
  248.        ("unoffable" "unoffable (1=yes)")
  249.        ("aistate" "current state"))
  250.   (states "art/misc.spe"
  251.       (stopped "off")
  252.       (blocking "on")))
  253.  
  254. */
  255.  
  256. (defun dead_object (current)
  257.   (if (>= current 0)
  258.       (let ((st (with_object (get_object current) (state))))
  259.     (if (or (eq st dead) (eq st blown_back_dead))
  260.         (let ((dead_guy (get_object current)))          
  261.           (remove_object (get_object current))
  262.           dead_guy)
  263.       (dead_object (- current 1))))
  264.     nil))
  265.  
  266. (defun death_re_ai ()
  267.   (if (> (total_objects) 1)
  268.       (let ((find (dead_object (- (total_objects) 1))))
  269.     (if find
  270.         (add_object (with_object (get_object 0) (otype)) 
  271.             (with_object find (x))
  272.             (with_object find (y))))))
  273.              
  274.   T)
  275.  
  276. (def_char  DEATH_RESPAWNER
  277.   (range 50 50)
  278.   (funs (ai_fun      death_re_ai)
  279.     (draw_fun    dev_draw))
  280.   (states "art/misc.spe"
  281.       (stopped "death_respawn")))
  282.  
  283.  
  284. (defun death_sen_ai () 
  285.   (if (eq (total_objects) 0)
  286.       (progn
  287.     (set_state running)
  288.     (set_aistate 1))
  289.     (if (with_object (get_object 0) (or (eq (state) dead) (eq (state) blown_back_dead)))
  290.     (remove_object (get_object 0))))
  291.   T)
  292.  
  293. (def_char  DEATH_SENSOR
  294.   (range 50 50)
  295.   (funs (ai_fun      death_sen_ai)
  296.     (draw_fun    dev_draw))
  297.   (states "art/misc.spe"
  298.       (stopped "death_sensor0")
  299.       (running "death_sensor1")))
  300.  
  301.  
  302.